package com.hellobike.haxing.modules.product.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hellobike.haxing.modules.product.entity.SkuStock;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
 * @Description: 销售库存
 * @Author: haxing-boot
 * @Date:   2020-02-10
 * @Version: V1.0
 */
public interface SkuStockMapper extends BaseMapper<SkuStock> {

    @Update("UPDATE t_sku_stock SET stock = stock + #{changeNum} WHERE sku_id = #{skuId} AND city_id = #{cityId} AND stock >= 0 - #{changeNum} AND deleted = 0")
    int changeSkuStock(@Param("skuId") Long skuId, @Param("cityId") Long cityId, @Param("changeNum") Integer changeNum);

}
